<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/18 0018
 * Time: 13:25
 */

namespace Cuke\Services;


use Cuke\Http\PageResult;
use Cuke\Models\CukeConnector;

class ConnectorService extends ServiceBase
{
    /**
     * 获取接口列表
     * @param int $pageIndex
     * @param int $pageSize
     * @param null|string|array $conditions
     * @return PageResult
     */
    public function getConnectorList($pageIndex = 1,$pageSize = 15,$conditions = null)
    {
        $where = '';
        $params = [];
        if(is_string($conditions)){
            $where .= $conditions;
        }elseif (is_array($conditions)){
            if(isset($conditions['conditions'])){
                $where .= $conditions['conditions'];
            }
            if(isset($conditions['bind'])){
                $params = array_merge($params,$conditions['bind']);
            }
        }
        $offset = ($pageIndex - 1) * $pageSize;

        $list = CukeConnector::find([
            $where,
            'bind'=>$params,
            'limit' => $offset.','.$pageSize
        ]);
        $totalCount = CukeConnector::count([
            $where,
            'bind'=>$params
        ]);

        return new PageResult($list,$totalCount);

    }
}